/*----------------------------输入账号------------------------------*/
$(function() {
	$("#g-bd .zhanghao input").blur(function() {
		var num = $("#g-bd .zhanghao input").val();
		var re = /^[a-z0-9A-Z]{6,18}$/;
		if(re.test(num)) {
			$("#g-bd .zhanghao .p1").css({
				"display": "block"
			});
			$("#g-bd .zhanghao .p2").css({
				"display": "none"
			});
		} else {
			$("#g-bd .zhanghao .p1").css({
				"display": "none"
			});
			$("#g-bd .zhanghao .p2").css({
				"display": "block"
			});
		}
	})

	/*----------------------------输入密码------------------------------*/

	$("#g-bd .mima input").blur(function() {
		var num1 = $("#g-bd .mima input").val();
		var re1 = /^[a-zA-Z]{5,16}$/;
		if(re1.test(num1)) {
			$("#g-bd .mima .p1").css({
				"display": "block"
			});
			$("#g-bd .mima .p2").css({
				"display": "none"
			});
		} else {
			$("#g-bd .mima .p1").css({
				"display": "none"
			});
			$("#g-bd .mima .p2").css({
				"display": "block"
			});
		}
	})

	/*----------------------------验证密码------------------------------*/

	$("#g-bd .yanzheng input").blur(function() {
		var num1 = $("#g-bd .mima input").val();
		var num2 = $("#g-bd .yanzheng input").val();
		if(num2 === num1) {
			$("#g-bd .yanzheng .p1").css({
				"display": "block"
			});
			$("#g-bd .yanzheng .p2").css({
				"display": "none"
			});
		} else {
			$("#g-bd .yanzheng .p1").css({
				"display": "none"
			});
			$("#g-bd .yanzheng .p2").css({
				"display": "block"
			});
		}
	})

	/*----------------------------随机验证码-----------------------------*/
	
	var btn = document.getElementsByClassName("shengcheng")[0]
	
	yzm();

	btn.onclick = function() {
		yzm();
	}
	
	function yzm(){
		var str = "";
		while(str.length < 4) {
			var num5 = Rand(48, 122)
			if((num5 >= 48 && num5 <= 57) || (num5 >= 65 && num5 <= 90) || (num5 >= 97 && num5 <= 122)) {
				str += String.fromCharCode(num5);
			}
		}
		btn.innerHTML = str;
		
	}
	
	function Rand(min, max) {
		return parseInt(Math.random() * (max - min + 1) + min);
	}
	
	
	/*----------------------------验证随机验证码-----------------------------*/
	$("#g-bd .sjsc .suiji").blur(function(){
		var suiji = $("#g-bd .sjsc .suiji").val() 
		var shengcheng = $("#g-bd .sjsc .shengcheng").html() 
		if( suiji === shengcheng) {
			$("#g-bd .sjsc .p1").css({
				"display": "block"
			});
			$("#g-bd .sjsc .p2").css({
				"display": "none"
			});
		} else {
			$("#g-bd .sjsc .p1").css({
				"display": "none"
			});
			$("#g-bd .sjsc .p2").css({
				"display": "block"
			});
		}

	})


	/*----------------------------手机号------------------------------*/

	$("#g-bd .number input").blur(function() {
		var num3 = $("#g-bd .number input").val();
		var re2 = /^1[3,4,5,7,8]\d{9}$/;
		if(re2.test(num3)) {
			$("#g-bd .number .p1").css({
				"display": "block"
			});
			$("#g-bd .number .p2").css({
				"display": "none"
			});
		} else {
			$("#g-bd .number .p1").css({
				"display": "none"
			});
			$("#g-bd .number .p2").css({
				"display": "block"
			});
		}
	})

})
	/*----------------------------验证------------------------------*/
	$(function(){
		$(".zhuce").click(function(){
			$.get("../check.php?username="+$("#username").val(),function(res){
				if(res=="true"){
					alert("用户名已被占用，请重新注册新用户名");
				}else{
					$.get("../charu.php?username="+$("#username").val()+"&psw="+$("#psw").val(),function(response){
						if(response=="ok"){
							alert("注册成功了");
						}else{
							alert("注册失败了");
						}
					})
				}
			})
		})
	})
	
